<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2019/1/9
 * Time: 22:02
 */
$server = new swoole_websocket_server("0.0.0.0", 8812);

$server->set([
    'enable_static_handler' => true,
    'document_root' => '/apps/wwwroot/swoole/data'
]);

$server->on('open', 'onOpen');
function onOpen(swoole_websocket_server $server,$request){
    echo "server: handshake success with fd{$request->fd}".PHP_EOL;
}

$server->on('message', 'onMessage');
function onMessage(swoole_websocket_server $server ,$frame){
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}".PHP_EOL;
    $server->push($frame->fd, "this is server push message");
}
$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});

$server->start();